<!--  -->
<style lang="less">
	.cate {
		height: 100vh;
		overflow: hidden;

		.content {
			display: flex;

			.left {
				height: calc(100vh - 100rpx);
				flex: 1;
				overflow: auto;

				.name {
					text-align: center;
					padding: 10rpx 0;
					font-size: 30rpx
				}

				.active {
					background-color: #007AFF;
				}
			}

			.right {
				height: calc(100vh - 100rpx);
				overflow: auto;
				flex: 3;
				background-color: #FFFFFF;

				.name {
					font-size: 30rpx;
					text-align: center;
				}

				.img_list {
					display: flex;
					flex-wrap: wrap;

					.img {
						text-align: center;
						width: 33%;

						.item_name {
							font-size: 30rpx
						}

						image {
							width: 70%;
						}
					}

				}
			}
		}
	}
</style>
<template>
	<view class="cate">
		<mybtn></mybtn>
		<view class="content">
			<view class="left">
				<view class="name" v-for="(item,index) in categories" :key="index" @click="cut(index)"
					:class="{active:index===childrenindex}">
					{{item.cat_name}}
				</view>
			</view>
			<view class="right">
				<view class="children" v-for="(item,index) in children" :key="index">
					<view class="name">
						{{item.cat_name}}
					</view>
					<view class="img_list">
						<view class="img" v-for="(i,n) in item.children" @click="goGoods(i.cat_id)" :key="n">
							<image :src="i.cat_icon" mode="widthFix"></image>
							<view class="item_name">
								{{i.cat_name}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		api
	} from "@/utils/index.js"
	export default {
		data() {
			return {
				categories: [],
				childrenindex: 0,
				children: []
			}
		},
		onLoad(o) {
			this.getcategories()
		},
		methods: {
			getcategories() {
				api({
					url: 'public/v1/categories'
				}).then(res => {
					this.categories = res.message
					this.children = res.message[this.childrenindex].children
					wx.hideLoading()
				})
			},
			cut(i) {
				this.childrenindex = i
				this.children = this.categories[this.childrenindex].children
			},
			goGoods(id) {
				uni.navigateTo({
					url: `/pages/goods_list/goods_list?id=${id}`
				});
			}
		}
	}
</script>
